import { Component, OnInit, Input, EventEmitter, Output, Injector } from '@angular/core';
import { TreeNode } from 'primeng/primeng';
import { Http } from '@angular/http';
import { TreeService } from 'app/public/serve/tree/tree.service';
import { Service } from 'app/server/server';
import { BaseTreeComponent } from '../base-tree/base-tree.component';

@Component({
  selector: 'app-resource-classify-tree',
  templateUrl: './resource-classify-tree.component.html',
  styleUrls: ['./resource-classify-tree.component.css']
})
export class ResourceClassifyTreeComponent extends BaseTreeComponent implements OnInit {

  constructor(
    injector: Injector
  ) {
    super(injector)
  }

  ngOnInit() {
    let type: string
    if (this.route.snapshot.url[0]) {
      //console.log(type)
      type = this.route.snapshot.url[0].path
    }
    let url = this.srv.baseUrl + 'product/resCategors/getProParentInfos'
    if (['periodical', 'article','wechatshares'].includes(type)) {
      url =this.srv.baseUrl + 'product/resCategors/getProParentInfos/1'
    } else {
      url =this.srv.baseUrl + 'product/resCategors/getProParentInfos/0'
    }
    this.treeSrv.getParentInfos(url, 'resCategoryId', 'resName').then((trees) => {
      if (trees) {
        this.data = trees;
      }
    }).catch(err => {
      console.error("产品管理资源分类树数据获取失败")
    })

    
  }

  public one1:any;
  ngOnDestroy() {
    this.one1 ? this.one1.unsubscribe() : '';
  }

}



